<?php

class Install extends Controller {

    function Install()
    {
        parent::Controller();
        $this->load->model('Model_controlpanel');
        $this->load->helper('url');
        $this->load->library('Installation');
    }

    function index()
    {
        if($_POST){
            if($this->installation->doInstall($_POST)){
                redirect("/home/index/true");
            }
        }else{
            // get folder permissions
            $filename = "./SMReceiver";
            $result = substr(sprintf('%o', fileperms($filename)), -4);
            if($result != "0777"){
                $data['folder_writable'] = false;
            }else{
                $data['folder_writable'] = true;
            }

            // get common page components
            $data['header'] = $this->load->view('header', '', true);
            $data['footer'] = $this->load->view('footer', '', true);

            $this->load->view('install_page', $data);
        }
    }

    function testconnection(){
        $host = $_POST['host'];
        $user = $_POST['user'];
        $password = $_POST['password'];
        $dbname = $_POST['dbname'];

        if(@mysql_connect($host, $user, $password)){
            if(mysql_select_db($dbname)){
                $result['feedback'] = "success";
            }else{
                $result['feedback'] = "failure";
            }
        }else{
            $result['feedback'] = "failure";
        }

        print json_encode($result);
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */